package edu.hawaii.duedates;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;

/**
 * Test case for the DueDates class. Tests for successful login, unsuccessful login, etc. Does not
 * test main method.
 * 
 * @author Scheller Sanchez and Tyler Wolff
 */

public class TestDueDates {

  // The user's UH ID number.
  private final String uhTestId1 = System.getenv("DUEDATES_TESTUSER1_ID");
  private final String uhTestId2 = System.getenv("DUEDATES_TESTUSER2_ID");

  // The user's last name.
  private final String lastTestName1 = System.getenv("DUEDATES_TESTUSER1_LASTNAME");
  private final String lastTestName2 = System.getenv("DUEDATES_TESTUSER2_LASTNAME");

  // Urls for the library's
  private static final String uhUrl = "http://uhmanoa.lib.hawaii.edu/cgi-bin/Pwebrecon.cgi?"
      + "DB=local&PAGE=pbLogon";
  private static final String hslUrl = "http://www.librarieshawaii.org/";

  /**
   * Tests uh login for the login method. Tests correct login info as well as incorrect login info.
   * 
   * @exception Exception if login errors.
   */
  @Test
  public void testLoginUh() throws Exception {

    // creating libraryVault object for UH Manoa Library
    LibraryVault uhManoa = new LibraryVault(uhUrl, "logonpage", "BC", "LN");

    // correct login
    WebConversation conversation = uhManoa.login(uhTestId2, lastTestName2);
    WebResponse response = conversation.getCurrentPage();
    assertNotNull("Testing correct Login", conversation);
    assertTrue("Testing correct Login Display", response.getText().contains("Checked Out Items"));

    // incorrect login
    conversation = uhManoa.login(uhTestId2 + "99", lastTestName2);
    assertNull("Testing incorrect Login", conversation);

  }

}